﻿#region Copyright information
// 
// Copyright © 2005-2013 Yongkee Cho. All rights reserved.
// 
// This code is a part of the Biological Object Library and governed under the terms of the
// GNU Lesser General  Public License (LGPL) version 2.1 which accompanies this distribution.
// For more information on the LGPL, please visit http://bol.codeplex.com/license.
// 
// - Filename: Subtract.cs
// - Author: Yongkee Cho
// - Email: yongkeecho@gmail.com
// - Date Created: 2012-11-05 11:28 AM
// - Last Modified: 2013-01-25 3:59 PM
// 
#endregion
using System;

namespace BOL.Linq.Matrix
{
    public static partial class Matrix
    {
        public static decimal[][] Subtract(this decimal[][] first, decimal[][] second)
        {
            if (first == null)
                throw new ArgumentNullException("first");
            if (second == null)
                throw new ArgumentNullException("second");

            var m = first.Length;
            var n = first[0].Length;

            if (second.Length != m || second[0].Length != n)
                throw new ArgumentOutOfRangeException("second");

            var temp = new decimal[m][];

            for (var i = 0; i < m; i++)
            {
                temp[i] = new decimal[n];
                for (var j = 0; j < n; j++)
                    temp[i][j] = first[i][j] - second[i][j];
            }

            return temp;
        }

        public static double[][] Subtract(this double[][] first, double[][] second)
        {
            if (first == null)
                throw new ArgumentNullException("first");
            if (second == null)
                throw new ArgumentNullException("second");

            var m = first.Length;
            var n = first[0].Length;

            if (second.Length != m || second[0].Length != n)
                throw new ArgumentOutOfRangeException("second");

            var temp = new double[m][];

            for (var i = 0; i < m; i++)
            {
                temp[i] = new double[n];
                for (var j = 0; j < n; j++)
                    temp[i][j] = first[i][j] - second[i][j];
            }

            return temp;
        }

        public static float[][] Subtract(this float[][] first, float[][] second)
        {
            if (first == null)
                throw new ArgumentNullException("first");
            if (second == null)
                throw new ArgumentNullException("second");

            var m = first.Length;
            var n = first[0].Length;

            if (second.Length != m || second[0].Length != n)
                throw new ArgumentOutOfRangeException("second");

            var temp = new float[m][];

            for (var i = 0; i < m; i++)
            {
                temp[i] = new float[n];
                for (var j = 0; j < n; j++)
                    temp[i][j] = first[i][j] - second[i][j];
            }

            return temp;
        }

        public static int[][] Subtract(this int[][] first, int[][] second)
        {
            if (first == null)
                throw new ArgumentNullException("first");
            if (second == null)
                throw new ArgumentNullException("second");

            var m = first.Length;
            var n = first[0].Length;

            if (second.Length != m || second[0].Length != n)
                throw new ArgumentOutOfRangeException("second");

            var temp = new int[m][];

            for (var i = 0; i < m; i++)
            {
                temp[i] = new int[n];
                for (var j = 0; j < n; j++)
                    temp[i][j] = first[i][j] - second[i][j];
            }

            return temp;
        }

        public static long[][] Subtract(this long[][] first, long[][] second)
        {
            if (first == null)
                throw new ArgumentNullException("first");
            if (second == null)
                throw new ArgumentNullException("second");

            var m = first.Length;
            var n = first[0].Length;

            if (second.Length != m || second[0].Length != n)
                throw new ArgumentOutOfRangeException("second");

            var temp = new long[m][];

            for (var i = 0; i < m; i++)
            {
                temp[i] = new long[n];
                for (var j = 0; j < n; j++)
                    temp[i][j] = first[i][j] - second[i][j];
            }

            return temp;
        }
    }
}
